define(function(require, exports, module) {

	var $ = require("jquery");

	var login = {

		init : function() {
			var img = $("img[src='idCode.do?method=randomIDCode']");
			img.click(function() {
				img.attr("src", "idCode.do?method=randomIDCode&time="
						+ Math.random());
			});

			var clientIDCode = $("input[name='clientIDCode']");
			clientIDCode.keyup(function() {
				var submit = $("input[type='submit']");
				if (clientIDCode.val().length == 4) {
					$.ajax({
						url : "idCode.do?method=checkIDCode",
						type : "post",
						data : {
							clientIDCode : clientIDCode.val()
						},
						success : function(data) {
							if (data == "success") {
								submit.removeAttr("disabled");
							} else {
								submit.attr("disabled", "disabled");
							}
						},
						error : function() {
							alert("发生错误！~");
						}
					});
				} else {
					submit.attr("disabled", "disabled");
				}
			});
		}

	}

	exports.init = function() {
		login.init();
	}

});